package com.example.goods.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;

/**
 * Created by IntelliJ IDEA.
 *响应信息
 * @author ouyangzhixiang
 * @date 2018/7/4
 */
@Getter
public class ResultResponse<T> {

    private Integer status;

    private String msg;

    private T data;


    private ResultResponse(Integer status) {
        this.status = status;
    }

    private ResultResponse(Integer status, T data) {
        this.status = status;
        this.data = data;
    }

    private ResultResponse(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }
    private ResultResponse(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }


    public boolean isSuccess(){
        return this.status.equals(ResponseCode.SUCCESS.getCode());
    }

    @JsonIgnore
    public static <T> ResultResponse<T> createBySuccess() {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode());
    }

    public static <T> ResultResponse<T> createBySuccessMessage(String msg) {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode(), msg);
    }

    public static <T> ResultResponse<T> createBySuccess(T data) {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode(), data);
    }

    public static <T> ResultResponse<T> createBySuccessMessage(String msg, T data) {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode(), msg, data);
    }

    public static <T> ResultResponse<T> createByError() {
        return new ResultResponse<T>(ResponseCode.FAILURE.getCode(), ResponseCode.FAILURE.getDesc());
    }

    public static <T> ResultResponse<T> createByErrorMessage(String errorMessage) {
        return new ResultResponse<T>(ResponseCode.FAILURE.getCode(), errorMessage);
    }

    public static <T> ResultResponse<T> createByErrorCodeMessage(int errorCode, String errorMessage) {
        return new ResultResponse<T>(errorCode, errorMessage);
    }

}
